/**
 *
 */
package com.czmh.etc.onlinepubsys.services.impl;

import com.alibaba.fastjson.JSONObject;
import com.czmh.etc.common.core.utils.Sequence;
import com.czmh.etc.interpreter.Utils.StringUtils;
import com.czmh.etc.interpreter.entity.base.EnMessagetype;
import com.czmh.etc.interpreter.entity.base.InterpreterContent;
import com.czmh.etc.interpreter.entity.request.*;
import com.czmh.etc.onlinepubsys.constants.GlobalStatusCode;
import com.czmh.etc.onlinepubsys.dto.EtcIdcardDto;
import com.czmh.etc.onlinepubsys.dto.EtcInterpreterMessageDto;
import com.czmh.etc.onlinepubsys.dto.EtcVehiclelicenseDto;
import com.czmh.etc.onlinepubsys.exceptions.EtcInterpreterException;
import com.czmh.etc.onlinepubsys.maper.*;
import com.czmh.etc.onlinepubsys.model.*;
import com.czmh.etc.onlinepubsys.request.ObuactivationRequest;
import com.czmh.etc.onlinepubsys.request.ObuconfirmRequest;
import com.czmh.etc.onlinepubsys.response.ObuactivationResponse;
import com.czmh.etc.onlinepubsys.services.EtcInterpreterService;
import com.czmh.etc.onlinepubsys.utils.GenerateCodeUtil;
import com.czmh.etc.onlinepubsys.utils.httpclient.HttpUtil;
import com.czmh.etc.onlinepubsys.utils.StringHexUtil;
import com.czmh.etc.onlinepubsys.utils.httpclient.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @描述：EtcInterpreterServiceImpl
 * @author： Seven.
 * @创建日期：Jun 11, 2019 8:17:18 PM.
 * @版本：1.0.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class EtcInterpreterServiceImpl implements EtcInterpreterService {
    private Logger logger = LoggerFactory.getLogger(EtcInterpreterServiceImpl.class);

    @Value("${yg.requestUrl}")
    private String ygrequestUrl;
    @Value("${yg.posid}")
    private String posid;
    @Value("${yg.TerminalID}")
    private String terminalID;
    @Value("${yg.bankId}")
    private String bankId;

    @Autowired
    private EtcUserMapper etcUserMapper;
    @Autowired
    private EtcApplyMapper etcApplyMapper;
    @Autowired
    private EtcIdcardMapper etcIdcardMapper;
    @Autowired
    private EtcVehiclelicenseMapper etcVehiclelicenseMapper;
    @Autowired
    private EtcCarMapper etcCarMapper;
    @Autowired
    private EtcObuMapper etcObuMapper;
    @Autowired
    private EtcOrderMapper etcOrderMapper;
    @Autowired
    private EtcCardMapper etcCardMapper;

    @Override
    public EtcInterpreterMessageDto registerEtcUserInfoRequest(EtcApply etcApply, EtcIdcardDto idcardDto, EtcVehiclelicenseDto vehiclelicenseDto) throws Exception {
        EtcInterpreterMessageDto registerUserMessage = this.registerUserInfo(etcApply, idcardDto);
        if (GlobalStatusCode.SUCCESS.equals(registerUserMessage.getFlag())) {
            EtcInterpreterMessageDto registerCarMessageDto = this.registerCarInfo(etcApply, idcardDto, vehiclelicenseDto);
            if (GlobalStatusCode.SUCCESS.equals(registerCarMessageDto.getFlag())) {
                return registerCarMessageDto;
            } else {
                throw new EtcInterpreterException(registerCarMessageDto.getFlag(), registerCarMessageDto.getMsg());
            }
        } else {
            throw new EtcInterpreterException(registerUserMessage.getFlag(), registerUserMessage.getMsg());
        }
    }

    /**
     * 注册用户信息：9133
     *
     * @param idcard       用户身份证信息
     * @return
     * @throws Exception
     */
    @Override
    public EtcInterpreterMessageDto registerUserInfo(EtcApply etcApply, EtcIdcardDto idcard) throws Exception {
        CardUserInfoOperateRequest request = new CardUserInfoOperateRequest();
        // 发送时间
        String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        request.setMsgLen(CardUserInfoOperateRequest.MSG_LEN);
        request.setMsgType(EnMessagetype.CardUserInfoOperateRequest);
        request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
        request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
        request.setSendTime(sendTimeStr);
        request.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
        request.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
        request.setPosID(posid);
        request.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));
        request.setGenTime(sendTimeStr);
        // 1：用户注册；2：信息修改；
        // 3：信息补录；4：用户注销
        request.setOptType("1");
        // 0：个人用户；1：单位用户；
        request.setUserType("0");
        request.setUserName(StringUtils.rightPadByByteLen(idcard.getName(), 60, ' '));
        request.setCertType(InterpreterContent.USER_CERT_TYPE);
        request.setCertSN(StringUtils.rightPadByByteLen(idcard.getNum(), 32, ' '));
        request.setLinkAddr(StringUtils.rightPadByByteLen(idcard.getAddress(), 100, ' '));
        request.setDepartment(StringUtils.rightPadByByteLen("", 100, ' '));
        // 开户方式：1-线上2-线下
        request.setRegisteredType("1");
        request.setAgentName(StringUtils.rightPadByByteLen("", 150, ' '));
        request.setAgentIdType(StringUtils.rightPadByByteLen("", 2, ' '));
        request.setAgentIdNum(StringUtils.rightPadByByteLen("", 30, ' '));
        // TODO 设置指定经办人电话
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", etcApply.getApply_id());
        List<EtcOrder> etcOrders = etcOrderMapper.getAll(params);
        EtcOrder etcOrder = etcOrders.get(0);
        request.setTel(StringUtils.rightPadByByteLen(etcOrder.getSh_phone(), 20, ' '));
        request.setBank(StringUtils.rightPadByByteLen("", 300, ' '));
        request.setBankAddr(StringUtils.rightPadByByteLen("", 300, ' '));
        request.setBankAccount(StringUtils.rightPadByByteLen("", 20, ' '));
        request.setTaxpayerCode(StringUtils.rightPadByByteLen("", 20, ' '));
        // 发送json请求
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = mapper.writeValueAsString(request);
        logger.info("接口编码：" + EnMessagetype.CardUserInfoOperateRequest.getMessageType() + "，json参数：" + jsonStr);
        return sendHttpRequest(EnMessagetype.CardUserInfoOperateRequest.getMessageType(), jsonStr);
    }

    /**
     * 注册车辆信息：9134
     *
     * @param idcardDto           用户身份证信息
     * @param vehiclelicenseDto   车辆行驶证信息
     * @return
     * @throws Exception
     */
    @Override
    public EtcInterpreterMessageDto registerCarInfo(EtcApply etcApply, EtcIdcardDto idcardDto, EtcVehiclelicenseDto vehiclelicenseDto) throws Exception {
        CardCarInfoOperateRequest request = new CardCarInfoOperateRequest();
        // 发送时间
        String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        request.setMsgLen(CardUserInfoOperateRequest.MSG_LEN);
        request.setMsgType(EnMessagetype.CardUserInfoOperateRequest);
        request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
        request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
        request.setSendTime(sendTimeStr);
        request.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
        request.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
        request.setPosID(posid);
        request.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));
        request.setGenTime(sendTimeStr);
        //操作类型 1：注册；2：修改;3:补录
        request.setOptType("1");
        //车牌号 14
        request.setVLP(StringUtils.rightPadByByteLen(vehiclelicenseDto.getPlate_num(), 14, ' '));
        //车牌底色 0：蓝；1：黄；2：黑；3：白；
        //4:渐变绿色5:黄绿双拼6:蓝白渐变
        //不允许变更
        request.setVLPC(etcApply.getApply_carlicencetyoe());
        //收费车型 2
        request.setVClass("01");
        //机动车所有人 50
        request.setOwnerName(StringUtils.rightPadByByteLen(vehiclelicenseDto.getOwner(), 50, ' '));
        //所有人证件类型 2
        request.setOwnerIdType(InterpreterContent.USER_CERT_TYPE);
        //所有人证件号
        request.setOwnerIdNum(StringUtils.rightPadByByteLen(idcardDto.getNum(), 30, ' '));
        //用户类型 0：个人用户；1：单位用户
        request.setUserType("0");
        //注册用户证件类型 2
        request.setCertType(InterpreterContent.USER_CERT_TYPE);
        //注册用户证件号 30
        request.setCertSN(StringUtils.rightPadByByteLen(idcardDto.getNum(), 30, ' '));
        //录入方式 1-线上2-线下
        request.setRegisteredType("1");
        //所有人联系电话    20
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", etcApply.getApply_id());
        List<EtcOrder> etcOrders = etcOrderMapper.getAll(params);
        EtcOrder etcOrder = etcOrders.get(0);
        request.setOwnerTel(StringUtils.rightPadByByteLen(etcOrder.getSh_phone(), 20, ' '));
        //联系地址      100
        request.setAddress(StringUtils.rightPadByByteLen(vehiclelicenseDto.getAddr(), 100, ' '));
        //联系人姓名    50
        request.setContact(StringUtils.rightPadByByteLen(vehiclelicenseDto.getOwner(), 50, ' '));
        //车辆类型      50
        request.setVehicleType(StringUtils.rightPadByByteLen(vehiclelicenseDto.getVehicle_type(), 50, ' '));
        //行驶证品牌型号  50
        request.setVehicleMode(StringUtils.rightPadByByteLen(vehiclelicenseDto.getModel(), 50, ' '));
        //车辆使用性质   4
        request.setUseCharacter(StringUtils.leftPadByByteLen(vehiclelicenseDto.getUse_character() == "非营运" ? "2" : "", 4, '0'));
        //车辆识别代号   50
        request.setVIN(StringUtils.rightPadByByteLen(vehiclelicenseDto.getVin(), 50, ' '));
        //车辆发动机号    50
        request.setEngineNum(StringUtils.rightPadByByteLen(vehiclelicenseDto.getEngine_num(), 50, ' '));
        //注册日期    20
        request.setRegisterDate(StringUtils.rightPadByByteLen(vehiclelicenseDto.getRegister_date(), 20, ' '));
        //发证日期   20
        request.setIssueDate(StringUtils.rightPadByByteLen(vehiclelicenseDto.getIssue_date(), 20, ' '));
        //档案编号   50
        request.setFileNum(StringUtils.rightPadByByteLen(vehiclelicenseDto.getFile_no(), 50, ' '));
        //定载人数   4
        String approvedCount = vehiclelicenseDto.getAppproved_passenger_capacity().replace("人", "");
        request.setApprovedCount(StringUtils.leftPadByByteLen(approvedCount, 4, '0'));
        //总质量    10
        String totalMass = vehiclelicenseDto.getGross_mass().replace("kg", "");
        request.setTotalMass(StringUtils.leftPadByByteLen(totalMass, 10, '0'));
        //整备质量   10
        String maintenanceMass = vehiclelicenseDto.getUnladen_mass().replace("kg", "");
        request.setMaintenanceMass(StringUtils.leftPadByByteLen(maintenanceMass, 10, '0'));
        //核定载质量  10
        request.setPermittedWeight(StringUtils.leftPadByByteLen(vehiclelicenseDto.getApproved_load() == null ? "" : vehiclelicenseDto.getApproved_load(), 10, '0'));
        //外廓尺寸   100
        String dimension = vehiclelicenseDto.getOverall_dimension().replace("x", "X");
        String outsideDimensions = dimension.replace("mm", "");
        request.setOutsideDimensions(StringUtils.rightPadByByteLen(outsideDimensions, 100, ' '));
        //牵引总质量  10
        request.setPermittedToWeight(StringUtils.leftPadByByteLen(vehiclelicenseDto.getTraction_mass() == null ? "" : vehiclelicenseDto.getTraction_mass(), 10, '0'));
        //检验记录    50
        request.setTestRecord(StringUtils.rightPadByByteLen(vehiclelicenseDto.getInspection_record() == null ? "" : vehiclelicenseDto.getInspection_record(), 50, ' '));
        //车轮数   4
        request.setWheelCount(StringUtils.leftPadByByteLen("4", 4, '0'));
        //车轴数   4
        request.setAxleCount(StringUtils.leftPadByByteLen("2", 4, '0'));
        //轴距    10
        request.setAxleDistance(StringUtils.leftPadByByteLen("0", 10, '0'));
        //轴型    50
        request.setAxisType(StringUtils.rightPadByByteLen("0", 50, ' '));
        // 发送json请求
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = mapper.writeValueAsString(request);
        logger.info("接口编码：" + EnMessagetype.CardCarInfoOperateRequest.getMessageType() + "，json参数：" + jsonStr);
        return sendHttpRequest(EnMessagetype.CardCarInfoOperateRequest.getMessageType(), jsonStr);
    }

    @Override
    public ObuactivationResponse obuactivation(ObuactivationRequest request) throws EtcInterpreterException, Exception {
        ObuactivationResponse data = new ObuactivationResponse();
        // 1.通过userid获取用户提交的申请信息
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", request.getApply_id());
        // 待审核的申请信息
        params.put("apply_status", 0);
        List<EtcApply> etcApplies = etcApplyMapper.getAll(params);
        EtcApply etcApply = etcApplies.get(0);
        // 添加车主身份证查询条件
        params.put("num", etcApply.getApply_idcard());
        List<EtcIdcard> list = etcIdcardMapper.getAll(params);
        // 用户身份证信息
        EtcIdcard etcIdcard = list.get(0);
        // 用户行驶证信息
        params.clear();
        params.put("car_id", etcApply.getCar_id());
        List<EtcVehiclelicense> vehiclelicenses = etcVehiclelicenseMapper.getAll(params);
        EtcVehiclelicense vehiclelicense = vehiclelicenses.get(0);
        EtcIdcardDto idcardDto = new EtcIdcardDto();
        EtcVehiclelicenseDto vehiclelicenseDto = new EtcVehiclelicenseDto();
        BeanUtils.copyProperties(etcIdcard, idcardDto);
        BeanUtils.copyProperties(vehiclelicense, vehiclelicenseDto);
        // 组装OBU激活请求参数
        OBUActivationRequest obuActivationRequest = new OBUActivationRequest();
        obuActivationRequest.setMsgLen(OBUActivationRequest.MSG_LEN);
        obuActivationRequest.setMsgType(EnMessagetype.OBUActivationRequest);
        obuActivationRequest.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
        obuActivationRequest.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
        String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        obuActivationRequest.setSendTime(sendTimeStr);
        obuActivationRequest.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
        obuActivationRequest.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
        obuActivationRequest.setPosID(posid);
        obuActivationRequest.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));

        // 1:发行，2:激活，3:重激活
        obuActivationRequest.setOperType("2");
        // 1:系统信息文件2:应用信息文件
        obuActivationRequest.setFileType("1");
        obuActivationRequest.setOBUID(StringUtils.rightPadByByteLen(request.getObuId(), 20, ' '));
        obuActivationRequest.setVLP(StringUtils.rightPadByByteLen(etcApply.getApply_carlicence(), 14, ' '));
        obuActivationRequest.setVLPC(etcApply.getApply_carlicencetyoe());
        obuActivationRequest.setVType("01");
        obuActivationRequest.setRandom(StringUtils.leftPadByByteLen(request.getRamdom(), 8, '0'));
        obuActivationRequest.setGenTime(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));

        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = mapper.writeValueAsString(obuActivationRequest);
        logger.info("接口编码：" + EnMessagetype.OBUActivationRequest.getMessageType() + "，json参数：" + jsonStr);
        EtcInterpreterMessageDto messageDto = sendHttpRequest(EnMessagetype.OBUActivationRequest.getMessageType(), jsonStr);
        if (GlobalStatusCode.SUCCESS.equals(messageDto.getFlag())) {
            JSONObject jsonObject = JSONObject.parseObject(messageDto.getResultStr());
            JSONObject dataObject = jsonObject.getJSONObject("data");
            data.setoBUInfo(dataObject.getString("OBUInfo"));
            // 更新OBU激活状态,激活地点等信息
            params.clear();
            params.put("obuid", request.getObuId());
            List<EtcObu> obuList = etcObuMapper.getAll(params);
            EtcObu etcObu = obuList.get(0);
            EtcObu update = new EtcObu(etcObu.getId());
            update.setActivate_status(1);
            update.setActivate_time(new Date());
            update.setProvince(request.getProvince());
            update.setCity(request.getCity());
            update.setArea(request.getArea());
            update.setActivate_addr(request.getActivate_addr());
            etcObuMapper.update(update);
            return data;
        } else {
            throw new EtcInterpreterException(messageDto.getFlag(), messageDto.getMsg());
        }
    }

    @Override
    public EtcInterpreterMessageDto cardSecSend(String user_id, String apply_id, String obu_id, String carId, String cardType, String vardVersion, String userType, String ramdom, String fileType) throws Exception {
        // 1.通过userid获取用户提交的申请信息
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", apply_id);
        // 待审核的申请信息
        params.put("apply_status", 0);
        List<EtcApply> etcApplies = etcApplyMapper.getAll(params);
        EtcApply etcApply = etcApplies.get(0);
        // 添加车主身份证查询条件
        params.put("num", etcApply.getApply_idcard());
        // 查询申办的身份证信息
        List<EtcIdcard> list = etcIdcardMapper.getAll(params);
        // 用户身份证信息
        EtcIdcard etcIdcard = list.get(0);
        // 用户行驶证信息
        params.clear();
        params.put("car_id", etcApply.getCar_id());
        List<EtcVehiclelicense> vehiclelicenses = etcVehiclelicenseMapper.getAll(params);
        EtcVehiclelicense vehiclelicense = vehiclelicenses.get(0);
        EtcIdcardDto idcardDto = new EtcIdcardDto();
        EtcVehiclelicenseDto vehiclelicenseDto = new EtcVehiclelicenseDto();
        BeanUtils.copyProperties(etcIdcard, idcardDto);
        BeanUtils.copyProperties(vehiclelicense, vehiclelicenseDto);
        // 发送时间
        String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        CardInfoChangeRequest request = new CardInfoChangeRequest();
        request.setMsgLen(CardInfoChangeRequest.MSG_LEN);
        request.setMsgType(EnMessagetype.CardInfoChangeRequest);
        request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
        request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
        request.setSendTime(sendTimeStr);
        request.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
        request.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
        request.setPosID(posid);
        request.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));
        // 2位银行代号+5位网点号
        request.setBankID("9101001");
        request.setGenTime(sendTimeStr);
        // 1：发行；2：变更
        request.setOptType('1');
        // 1:0015文件；2：0016文件
        request.setFileType(fileType.charAt(0));
        // TODO 银行卡账号参数AccountID，储值卡可以默认0 记账卡需要填写具体的扣款账号
        request.setAccountID(StringUtils.rightPadByByteLen("8237346764828372", 19, '0'));
        // 22：储值卡；23：记账卡，将16进制卡类型转为10进制字符串
        String card = String.valueOf(Long.parseLong(cardType, 16));
        request.setCardType(card);
        /**
         * 第1位：1-记账卡2-储值卡
         * 第2位：1-独立账户2-绑定贷记卡账户3-绑定借记卡账户4-绑定其他支付账户5-绑定银行对公账户
         * 第3位：1-单卡2-二卡分离3-二卡合一
         * 独立账户卡为单卡
         */
        // TODO 设置银行卡绑卡账户
        String accType = "";
        if ("22".equals(card)) {
//            accType =
        }
        request.setAccType("211");
        /**
         * 1、按时间划账；2、按额度划账；3、自由划账；（银行暂时先都填按时间划账，并且天数为1）
         */
        request.setTransType('1');
        // TODO
        request.setTransferLimit(new BigDecimal(10000));
        request.setTallyLimit(new BigDecimal(1000));
        request.setCardID(carId);
        /**
         * 0：个人用户；1：集团用户；（默认都填个人用户）
         * 3、应急车个人用户
         * 4、应急车集团用户
         */
        request.setUserType(String.valueOf(Long.parseLong(userType, 16)).charAt(0));
        request.setUserName(StringUtils.rightPadByByteLen(etcIdcard.getName(), 60, ' '));
        request.setCertType(InterpreterContent.USER_CERT_TYPE);
        request.setCertSN(StringUtils.rightPadByByteLen(etcIdcard.getNum(), 32, ' '));
        request.setCardCost(00000000);
        request.setLinkAddr(StringUtils.rightPadByByteLen(etcIdcard.getAddress(), 100, ' '));

        request.setLinkPost(StringUtils.rightPadByByteLen("", 6, ' '));
        request.setLinkTel(StringUtils.rightPadByByteLen("", 16, ' '));
        request.setLinkMobile(StringUtils.rightPadByByteLen("", 16, ' '));
        request.setLinkFax(StringUtils.rightPadByByteLen("", 16, ' '));
        request.setLinkMail(StringUtils.rightPadByByteLen("", 60, ' '));

        request.setVLP(StringUtils.rightPadByByteLen(vehiclelicense.getPlate_num(), 14, ' '));
        // 0：蓝；1：黄；2：黑；3：白；
        //4:渐变绿色5:黄绿双拼6:蓝白渐变
        request.setVLPC(etcApply.getApply_carlicencetyoe().charAt(0));
        //01-04：客1-客4；11-15：货1-货5；16：集1；17：集2
        //21-24:1/2/3/4型专项作业车
        request.setVclass("01");
        request.setRandom(StringUtils.leftPadByByteLen(ramdom, 8, '0'));
        // 区分新老国标两种版本的青通联名卡，新国标卡版本号20，老国标卡版本号10，增加ETC全国联网新国标版本号为40
        request.setCardVer(vardVersion);
        // TODO
        request.setBrand("02");
        // 1-线上2-线下
        request.setIssuedType('1');
        // 卡片型号
        // TODO
        request.setModel(StringUtils.rightPadByByteLen("", 20, ' '));

        // 发送json请求
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = mapper.writeValueAsString(request);
        logger.info("接口编码：" + EnMessagetype.CardInfoChangeRequest.getMessageType() + "，json参数：" + jsonStr);
        EtcInterpreterMessageDto messageDto = sendHttpRequest(EnMessagetype.CardInfoChangeRequest.getMessageType(), jsonStr);
        if (GlobalStatusCode.SUCCESS.equals(messageDto.getFlag())) {
            // 记录用户的卡信息
            params.clear();
            params.put("card_id", carId);
            List<EtcCard> etcCards = etcCardMapper.getAll(params);
            if (etcCards.isEmpty()) {
                EtcCard etcCard = new EtcCard(carId);
                etcCard.setObu_id(obu_id);
                etcCard.setCar_num(vehiclelicense.getPlate_num());
                etcCard.setCard_id(vehiclelicense.getCar_id());
                Long type = Long.parseLong(cardType, 16);
                etcCard.setCard_type(type.intValue());
                etcCard.setCreate_time(new Date());
                etcCard.setUpdate_time(new Date());
                etcCard.setUser_id(etcApply.getUser_id());
                Long user_type = Long.parseLong(userType, 16);
                etcCard.setUser_type(user_type.intValue());
                etcCardMapper.insert(etcCard);
            }
            return messageDto;
        } else {
            throw new EtcInterpreterException(messageDto.getFlag(), messageDto.getMsg());
        }
    }

    @Override
    public EtcInterpreterMessageDto obuSecSend(String user_id, String apply_id, String obuId, String userType, String fileType, String ramdom) throws EtcInterpreterException, Exception {
        // 1.通过userid获取用户提交的申请信息
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", apply_id);
        // 待审核的申请信息
        params.put("apply_status", 0);
        List<EtcApply> etcApplies = etcApplyMapper.getAll(params);
        EtcApply etcApply = etcApplies.get(0);
        // 添加车主身份证查询条件
        params.put("num", etcApply.getApply_idcard());
        List<EtcIdcard> list = etcIdcardMapper.getAll(params);
        // 用户身份证信息
        EtcIdcard etcIdcard = list.get(0);
        // 用户行驶证信息
        params.clear();
        params.put("car_id", etcApply.getCar_id());
        List<EtcVehiclelicense> vehiclelicenses = etcVehiclelicenseMapper.getAll(params);
        EtcVehiclelicense vehiclelicense = vehiclelicenses.get(0);
        EtcIdcardDto idcardDto = new EtcIdcardDto();
        EtcVehiclelicenseDto vehiclelicenseDto = new EtcVehiclelicenseDto();
        BeanUtils.copyProperties(etcIdcard, idcardDto);
        BeanUtils.copyProperties(vehiclelicense, vehiclelicenseDto);
        // 首先判断文件类型是否为1，如果为1则需要先调用9104注册OBU，再调用9139传递operType：1，Filetype：1获取写入OBU系统信息指令
        if ("1".equals(fileType)) {
            // 1.调用9104接口注册OBU
            String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            OBUInfoChangeRequest request = new OBUInfoChangeRequest();
            request.setMsgLen(OBUInfoChangeRequest.MSG_LEN);
            request.setMsgType(EnMessagetype.OBUInfoChangeRequest);
            request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
            request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
            request.setSendTime(sendTimeStr);
            request.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
            request.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
            request.setPosID(posid);
            request.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));
            request.setGenTime(sendTimeStr);
            // 1：发行；2：变更
            request.setOptType("1");
            request.setOBUID(StringUtils.rightPadByByteLen(obuId, 20, ' '));
            // 0：个人用户；1：集团用户
            //3、应急车个人用户
            //4、应急车集团用户
            request.setUserType(String.valueOf(Long.parseLong(userType, 16)));
            request.setUserName(StringUtils.rightPadByByteLen(idcardDto.getName(), 60, ' '));
            request.setCertType(InterpreterContent.USER_CERT_TYPE);
            request.setCertSN(StringUtils.rightPadByByteLen(idcardDto.getNum(), 32, ' '));
            String cap = vehiclelicense.getAppproved_passenger_capacity().substring(0, 1);
            request.setWeight(StringUtils.leftPadByByteLen(cap, 10, '0'));
            String overall_dimension = vehiclelicense.getOverall_dimension();
            String[] size = overall_dimension.split("X");
            request.setVehWeight(StringUtils.leftPadByByteLen(size[0], 5, '0'));
            request.setVehWidth(StringUtils.leftPadByByteLen(size[1], 5, '0'));
            request.setVehHeight(StringUtils.leftPadByByteLen(size[2].substring(0,4), 5, '0'));
            //车轮数   4
            request.setWheelNum("04");
            //轴距    5
            request.setWheelbase(StringUtils.leftPadByByteLen("0", 5, '0'));
            //车轴数   4
            request.setAxleNum("02");
            request.setCardCost(StringUtils.leftPadByByteLen("2000", 8, '0'));
            request.setLinkAddr(StringUtils.rightPadByByteLen(idcardDto.getAddress(), 100, ' '));
            request.setLinkPost(StringUtils.rightPadByByteLen("", 6, ' '));
            request.setLinkTel(StringUtils.rightPadByByteLen("", 16, ' '));
            request.setLinkMobile(StringUtils.rightPadByByteLen("", 16, ' '));
            request.setLinkFax(StringUtils.rightPadByByteLen("", 16, ' '));
            request.setLinkMail(StringUtils.rightPadByByteLen("", 60, ' '));
            request.setVModel(StringUtils.rightPadByByteLen("", 40, ' '));
            // TODO 设置车辆颜色
            request.setVLC("5");
            request.setVLPC(etcApply.getApply_carlicencetyoe());
            request.setVLP(StringUtils.rightPadByByteLen(vehiclelicense.getPlate_num(), 14, ' '));
            // TODO 设置关联车型，01-04：客1-客4；OBU只允许发给客车
            request.setVClass("01");
            request.setVopera(vehiclelicense.getUse_character() == "非营运" ? "2" : "1");
            request.setVEngineNum(StringUtils.rightPadByByteLen(vehiclelicense.getEngine_num(), 18, ' '));
            // OBU品牌:埃特斯2-金溢3-聚利4-东海5-航天信息6-千方7-万集8-中兴9-握奇10-搜林
            //11-成谷12-云星宇13-华虹14-黔通电子15-通行宝16-赛格，
            //如有非列举卡品牌需向路网中心报备
            request.setBrand("02");
            // OBU注册方式:1-线上2-线下
            request.setRegisteredType("1");
            request.setModel(StringUtils.rightPadByByteLen("Sophia-V60c+", 20, ' '));

            // 发送json请求
            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(request);
            logger.info("接口编码：" + EnMessagetype.OBUInfoChangeRequest.getMessageType() + "，json参数：" + jsonStr);
            EtcInterpreterMessageDto message = sendHttpRequest(EnMessagetype.OBUInfoChangeRequest.getMessageType(), jsonStr);
            if (GlobalStatusCode.SUCCESS.equals(message.getFlag())) {
                // 2.调用9139发行OBU
                String obusendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
                OBUActivationRequest obuActivationRequest = new OBUActivationRequest();
                obuActivationRequest.setMsgLen(OBUActivationRequest.MSG_LEN);
                obuActivationRequest.setMsgType(EnMessagetype.OBUActivationRequest);
                obuActivationRequest.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
                obuActivationRequest.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
                obuActivationRequest.setSendTime(obusendTimeStr);
                obuActivationRequest.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
                request.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
                request.setPosID(posid);
                request.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));
                // 1:发行，2:激活，3:重激活
                obuActivationRequest.setOperType("1");
                // 1:系统信息文件2:应用信息文件
                obuActivationRequest.setFileType(fileType);
                obuActivationRequest.setOBUID(StringUtils.rightPadByByteLen(obuId, 20, ' '));
                obuActivationRequest.setVLP(StringUtils.rightPadByByteLen(etcApply.getApply_carlicence(), 14, ' '));
                obuActivationRequest.setVLPC(etcApply.getApply_carlicencetyoe());
                obuActivationRequest.setVType("01");
                obuActivationRequest.setRandom(StringUtils.leftPadByByteLen(ramdom, 8, '0'));
                obuActivationRequest.setGenTime(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));
                ObjectMapper mapper2 = new ObjectMapper();
                String jsonStr2 = mapper2.writeValueAsString(obuActivationRequest);
                logger.info("接口编码：" + EnMessagetype.OBUActivationRequest.getMessageType() + "，json参数：" + jsonStr2);
                EtcInterpreterMessageDto messageDto = sendHttpRequest(EnMessagetype.OBUActivationRequest.getMessageType(), jsonStr2);
                if (GlobalStatusCode.SUCCESS.equals(messageDto.getFlag())) {
                    params.clear();
                    params.put("obuid", obuId);
                    List<EtcObu> etcObuList = etcObuMapper.getAll(params);
                    if (!etcObuList.isEmpty() && etcObuList.size() == 1) {
                        // 更新发行的OBU设备记录
                        Long user_type = Long.parseLong(userType, 16);
                        JSONObject jsonObject = JSONObject.parseObject(messageDto.getResultStr());
                        JSONObject dataObject = jsonObject.getJSONObject("data");
                        String user_time = dataObject.getString("UseTime");
                        String expire_time = dataObject.getString("ExpireTime");
                        EtcObu updateetcObu = new EtcObu(etcObuList.get(0).getId());
                        updateetcObu.setRegisteredtype(1);
                        updateetcObu.setCar_id(vehiclelicense.getCar_id());
                        updateetcObu.setApply_id(apply_id);
                        updateetcObu.setUser_type(user_type.intValue());
                        updateetcObu.setActivate_status(1);
                        updateetcObu.setUse_time(user_time);
                        updateetcObu.setExpire_time(expire_time);
                        etcObuMapper.update(updateetcObu);
                    } else {
                        // 保存发行的OBU设备记录
                        EtcObu etcObu = new EtcObu(Sequence.getId());
                        etcObu.setObuid(obuId);
                        etcObu.setObucost(200);
                        etcObu.setObubrand("02");
                        etcObu.setObumodel("Sophia-V60c+");
                        etcObu.setRegisteredtype(1);
                        etcObu.setCar_id(vehiclelicense.getCar_id());
                        etcObu.setCreate_time(new Date());
                        etcObu.setApply_id(apply_id);
                        Long user_type = Long.parseLong(userType, 16);
                        etcObu.setUser_type(user_type.intValue());
                        JSONObject jsonObject = JSONObject.parseObject(messageDto.getResultStr());
                        JSONObject dataObject = jsonObject.getJSONObject("data");
                        String user_time = dataObject.getString("UseTime");
                        String expire_time = dataObject.getString("ExpireTime");
                        etcObu.setUse_time(user_time);
                        etcObu.setExpire_time(expire_time);
                        etcObu.setCreate_time(new Date());
                        etcObuMapper.insert(etcObu);
                    }
                    return messageDto;
                } else {
                    throw new EtcInterpreterException(messageDto.getFlag(), messageDto.getMsg());
                }
            } else {
                throw new EtcInterpreterException(message.getFlag(), message.getMsg());
            }
        } else if("2".equals(fileType)) {
            // 发送9139报文（Opertype：2，Filetype：1）请求返回写入OBU应用信息指令
            // 2.调用9139发行OBU
            String obusendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            OBUActivationRequest obuActivationRequest = new OBUActivationRequest();
            obuActivationRequest.setMsgLen(OBUActivationRequest.MSG_LEN);
            obuActivationRequest.setMsgType(EnMessagetype.OBUActivationRequest);
            obuActivationRequest.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
            obuActivationRequest.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
            obuActivationRequest.setSendTime(obusendTimeStr);
            obuActivationRequest.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
            obuActivationRequest.setWasteSn(bankId + obusendTimeStr + GenerateCodeUtil.generateValidCode(4));
            obuActivationRequest.setPosID(posid);
            obuActivationRequest.setTerminalID(StringUtils.rightPadByByteLen(terminalID, 14, ' '));
            // 1:发行，2:激活，3:重激活
            obuActivationRequest.setOperType("1");
            // 1:系统信息文件2:应用信息文件
            obuActivationRequest.setFileType(fileType);
            obuActivationRequest.setOBUID(StringUtils.rightPadByByteLen(obuId, 20, ' '));
            obuActivationRequest.setVLP(StringUtils.rightPadByByteLen(StringHexUtil.hexStringToString(etcApply.getApply_carlicence()), 14, ' '));
            obuActivationRequest.setVLPC(etcApply.getApply_carlicencetyoe());
            obuActivationRequest.setVType("01");
            obuActivationRequest.setRandom(StringUtils.leftPadByByteLen(ramdom, 8, '0'));
            obuActivationRequest.setGenTime(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));
            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(obuActivationRequest);
            logger.info("接口编码：" + EnMessagetype.OBUActivationRequest.getMessageType() + "，json参数：" + jsonStr);
            EtcInterpreterMessageDto messageDto = sendHttpRequest(EnMessagetype.OBUActivationRequest.getMessageType(), jsonStr);
            if (GlobalStatusCode.SUCCESS.equals(messageDto.getFlag())) {
                return messageDto;
            } else {
                throw new EtcInterpreterException(messageDto.getFlag(), messageDto.getMsg());
            }
        }
        return null;
    }

    @Override
    public void obuconfirm(String user_id, ObuconfirmRequest obuconfirmRequest) throws EtcInterpreterException, Exception {
        ObuactivationResponse data = new ObuactivationResponse();
        // 1.通过apply_id获取用户提交的申请信息
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", obuconfirmRequest.getApply_id());
        // 待审核的申请信息
        params.put("apply_status", 0);
        List<EtcApply> etcApplies = etcApplyMapper.getAll(params);
        EtcApply etcApply = etcApplies.get(0);
        // 添加车主身份证查询条件
        params.put("num", etcApply.getApply_idcard());
        List<EtcIdcard> list = etcIdcardMapper.getAll(params);
        // 用户身份证信息
        EtcIdcard etcIdcard = list.get(0);
        // 用户行驶证信息
        params.clear();
        params.put("car_id", etcApply.getCar_id());
        List<EtcVehiclelicense> vehiclelicenses = etcVehiclelicenseMapper.getAll(params);
        EtcVehiclelicense vehiclelicense = vehiclelicenses.get(0);
        EtcIdcardDto idcardDto = new EtcIdcardDto();
        EtcVehiclelicenseDto vehiclelicenseDto = new EtcVehiclelicenseDto();
        BeanUtils.copyProperties(etcIdcard, idcardDto);
        BeanUtils.copyProperties(vehiclelicense, vehiclelicenseDto);
        String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        OBUIssuerResultRequest request = new OBUIssuerResultRequest();
        request.setMsgLen(OBUInfoChangeRequest.MSG_LEN);
        request.setMsgType(EnMessagetype.OBUInfoChangeRequest);
        request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
        request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
        request.setSendTime(sendTimeStr);
        request.setVerifyCode(new Long(GenerateCodeUtil.generateValidCode(9)));
        request.setWasteSn(bankId + sendTimeStr + GenerateCodeUtil.generateValidCode(4));
        request.setPosID(posid);
        request.setTerminalID(terminalID);
        request.setGenTime(sendTimeStr);
        // 0：处理成功；1：处理失败
        request.setFlag(obuconfirmRequest.getFlag());
        // 1：发行；2：变更
        request.setOptType("1");
        request.setOBUID(StringUtils.rightPadByByteLen(obuconfirmRequest.getObuId(), 20, ' '));
        // 0：个人用户；1：集团用户
        request.setUserType(String.valueOf(Long.parseLong(obuconfirmRequest.getUserType(), 16)));
        request.setUserName(StringUtils.rightPadByByteLen(idcardDto.getName(), 60, ' '));
        request.setCertType(InterpreterContent.USER_CERT_TYPE);
        request.setCertSN(StringUtils.rightPadByByteLen(idcardDto.getNum(), 32, ' '));
        request.setVLP(StringUtils.rightPadByByteLen(StringHexUtil.hexStringToString(etcApply.getApply_carlicence()), 14, ' '));
        request.setVLPC(etcApply.getApply_carlicencetyoe());
        //收费车型 2
        request.setVClass("01");
        params.clear();
        params.put("obuid", obuconfirmRequest.getObuId());
        List<EtcObu> etcObus = etcObuMapper.getAll(params);
        EtcObu etcObu = etcObus.get(0);
        request.setUseTime(StringUtils.rightPadByByteLen(etcObu.getUse_time(), 14, ' '));
        request.setExpireTime(StringUtils.rightPadByByteLen(etcObu.getExpire_time(), 14, ' '));
        // OBU安装方式:1-自行安装2-网点安装
        request.setInstallType("1");
        // 发送json请求
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = mapper.writeValueAsString(request);
        logger.info("接口编码：" + EnMessagetype.OBUActivationRequest.getMessageType() + "，json参数：" + jsonStr);
        EtcInterpreterMessageDto messageDto = sendHttpRequest(EnMessagetype.OBUActivationRequest.getMessageType(), jsonStr);
        if (!GlobalStatusCode.SUCCESS.equals(messageDto.getFlag())) {
            throw new EtcInterpreterException(messageDto.getFlag(), messageDto.getMsg());
        }
    }

    @Override
    public EtcInterpreterMessageDto registerinfo(String user_id, String apply_id) throws EtcInterpreterException, Exception {
        // 1.通过apply_id获取用户提交的申请信息
        Map<String, Object> params = new HashMap<String, Object>(0);
        params.put("apply_id", apply_id);
        // 待审核的申请信息
        params.put("apply_status", 0);
        List<EtcApply> etcApplies = etcApplyMapper.getAll(params);
        EtcApply etcApply = etcApplies.get(0);
        // 添加车主身份证查询条件
        params.put("num", etcApply.getApply_idcard());
        List<EtcIdcard> list = etcIdcardMapper.getAll(params);
        // 用户身份证信息
        EtcIdcard etcIdcard = list.get(0);
        // 用户行驶证信息
        params.clear();
        params.put("car_id", etcApply.getCar_id());
        List<EtcVehiclelicense> vehiclelicenses = etcVehiclelicenseMapper.getAll(params);
        EtcVehiclelicense vehiclelicense = vehiclelicenses.get(0);
        EtcIdcardDto idcardDto = new EtcIdcardDto();
        EtcVehiclelicenseDto vehiclelicenseDto = new EtcVehiclelicenseDto();
        BeanUtils.copyProperties(etcIdcard, idcardDto);
        BeanUtils.copyProperties(vehiclelicense, vehiclelicenseDto);
        return this.registerEtcUserInfoRequest(etcApply, idcardDto, vehiclelicenseDto);
    }

    /**
     * 发送http请求请求青海接口
     *
     * @param msgType 接口类型
     * @param jsonStr 请求参数字符串
     * @return
     * @throws IOException
     */
    private EtcInterpreterMessageDto sendHttpRequest(int msgType, String jsonStr) throws IOException {
        EnMessagetype enMessagetype = EnMessagetype.loadEnMessageTypeEnum(msgType);
        String url = ygrequestUrl;
        EtcInterpreterMessageDto data = null;
        Result result = null;
        String resultStr = null;
        JSONObject jsonObject = null;
        JSONObject dataObject = null;
        String flag = "";
        switch (enMessagetype) {
            // 9133
            case CardUserInfoOperateRequest:
                url = url + msgType;
                logger.info("请求地址：" + url);
                data = new EtcInterpreterMessageDto();
                result = HttpUtil.httpPost(url, jsonStr);
                resultStr = result.getBody();
                logger.info("请求参数：{}", jsonStr);
                logger.info("返回结果：{}", resultStr);
                jsonObject = JSONObject.parseObject(resultStr);
                dataObject = jsonObject.getJSONObject("data");
                flag = dataObject.getString("Flag");
                /**
                 * 0：成功； 1：用户注册失败；
                 * 2：该用户未注册不允许补录或修改
                 * 3: 该用户已注册；
                 * 4：终端校验失败
                 */
                if ("0".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "成功", resultStr);
                } else if ("1".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "用户注册失败", resultStr);
                } else if ("2".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "该用户未注册不允许补录或修改", resultStr);
                } else if ("3".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "该用户已注册", resultStr);
                } else if ("4".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "终端校验失败", resultStr);
                }
                break;
            // 9134
            case CardCarInfoOperateRequest:
                url = url + msgType;
                logger.info("请求地址：" + url);
                data = new EtcInterpreterMessageDto();
                result = HttpUtil.httpPost(url, jsonStr);
                resultStr = result.getBody();
                logger.info("请求参数：{}", jsonStr);
                logger.info("返回结果：{}", resultStr);
                jsonObject = JSONObject.parseObject(resultStr);
                dataObject = jsonObject.getJSONObject("data");
                flag = dataObject.getString("Flag");
                flag = dataObject.getString("Flag");
                /**
                 0：成功，1：车辆信息注册失败，2：注册车辆已发卡请补录3：终端不合法，
                 4：该车辆未注册无法变更5：车型不允许修改。6车辆信息不符合营改增规格
                 */
                if ("0".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "成功", resultStr);
                } else if ("1".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "车辆信息注册失败", resultStr);
                } else if ("2".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "注册车辆已发卡请补录", resultStr);
                } else if ("3".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "终端不合法", resultStr);
                } else if ("4".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "该车辆未注册无法变更", resultStr);
                } else if ("5".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "车型不允许修改", resultStr);
                } else if ("6".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "车辆信息不符合营改增规格", resultStr);
                }
                break;
            // 9102
            case CardInfoChangeRequest:
                url = url + msgType;
                logger.info("请求地址：" + url);
                data = new EtcInterpreterMessageDto();
                result = HttpUtil.httpPost(url, jsonStr);
                resultStr = result.getBody();
                logger.info("请求参数：{}", jsonStr);
                logger.info("返回结果：{}", resultStr);
                jsonObject = JSONObject.parseObject(resultStr);
                dataObject = jsonObject.getJSONObject("data");
                flag = dataObject.getString("Flag");
                /**
                 * 0：成功； 1：失败；2：一次发行卡字典中不存在该卡；3：信息变更卡不存在或者卡状态不正确；
                 * 4：信息变更卡所属用户不存在或者状态不正确；
                 * 5:该车辆已经发行过青通联名卡；
                 * 6：终端校验失败
                 * 7：变更车牌号已经存在
                 * 8：变更车牌无车辆信息需注册
                 * 9、信息不符合规则。
                 */
                if ("0".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "成功", resultStr);
                } else if ("1".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "失败", resultStr);
                } else if ("2".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "一次发行卡字典中不存在该卡", resultStr);
                } else if ("3".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "信息变更卡不存在或者卡状态不正确", resultStr);
                } else if ("4".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "信息变更卡所属用户不存在或者状态不正确", resultStr);
                } else if ("5".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "该车辆已经发行过青通联名卡", resultStr);
                } else if ("6".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "终端校验失败", resultStr);
                } else if ("7".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "变更车牌号已经存在", resultStr);
                } else if ("8".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "变更车牌无车辆信息需注册", resultStr);
                } else if ("9".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "信息不符合规则", resultStr);
                }
                break;
            // 9104
            case OBUInfoChangeRequest:
                url = url + msgType;
                logger.info("请求地址：" + url);
                data = new EtcInterpreterMessageDto();
                result = HttpUtil.httpPost(url, jsonStr);
                resultStr = result.getBody();
                logger.info("请求参数：{}", jsonStr);
                logger.info("返回结果：{}", resultStr);
                jsonObject = JSONObject.parseObject(resultStr);
                dataObject = jsonObject.getJSONObject("data");
                flag = dataObject.getString("Flag");
                /**
                 * 0：成功； 1：用户注册失败；
                 * 2：OBU一次发行字典表中不存在；
                 * 3：信息变更卡不存在或者OBU状态不正确；
                 * 4：信息变更卡所属用户不存在或者状态不正确；
                 * 5：该车辆已经发行过OBU；
                 * 6：终端校验失败；
                 * 7：未发行青通卡
                 * 8:变更车牌已存在
                 * 9变更信息不符合规则。
                 */
                if ("0".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "成功", resultStr);
                } else if ("1".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "用户注册失败", resultStr);
                } else if ("2".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "OBU一次发行字典表中不存在", resultStr);
                } else if ("3".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "信息变更卡不存在或者OBU状态不正确", resultStr);
                } else if ("4".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "信息变更卡所属用户不存在或者状态不正确", resultStr);
                } else if ("5".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "该车辆已经发行过OBU", resultStr);
                } else if ("6".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "终端校验失败", resultStr);
                } else if ("7".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "未发行青通卡", resultStr);
                } else if ("8".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "变更车牌已存在", resultStr);
                } else if ("9".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "变更信息不符合规则", resultStr);
                }
                break;
            // 9139
            case OBUActivationRequest:
                url = url + msgType;
                logger.info("请求地址：" + url);
                data = new EtcInterpreterMessageDto();
                result = HttpUtil.httpPost(url, jsonStr);
                resultStr = result.getBody();
                logger.info("请求参数：{}", jsonStr);
                logger.info("返回结果：{}", resultStr);
                jsonObject = JSONObject.parseObject(resultStr);
                dataObject = jsonObject.getJSONObject("data");
                flag = dataObject.getString("Flag");
                /**
                 * 0:成功，
                 * 1:车牌号不一致，
                 * 2：车牌号一致车牌颜色不一致,
                 * 3：车型不一致，
                 * 4:计算MAC失败。
                 * 5:终端校验失败。
                 * 6:校验OBU信息失败
                 */
                if ("0".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "成功", resultStr);
                } else if ("1".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "车牌号不一致", resultStr);
                } else if ("2".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "车牌号一致车牌颜色不一致", resultStr);
                } else if ("3".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "车型不一致", resultStr);
                } else if ("4".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "计算MAC失败", resultStr);
                } else if ("5".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "终端校验失败", resultStr);
                } else if ("6".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "校验OBU信息失败", resultStr);
                }
                break;
            // 9126
            case OBUIssuerResultRequest:
                url = url + msgType;
                logger.info("请求地址：" + url);
                data = new EtcInterpreterMessageDto();
                result = HttpUtil.httpPost(url, jsonStr);
                resultStr = result.getBody();
                logger.info("请求参数：{}", jsonStr);
                logger.info("返回结果：{}", resultStr);
                jsonObject = JSONObject.parseObject(resultStr);
                dataObject = jsonObject.getJSONObject("data");
                flag = dataObject.getString("Flag");
                /**
                 * 0：成功；1：失败；3：终端校验失败
                 */
                if ("0".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "成功", resultStr);
                } else if ("1".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "失败", resultStr);
                } else if ("3".equals(flag)) {
                    data = new EtcInterpreterMessageDto(flag, "终端校验失败", resultStr);
                }
                break;
            default:
                return data;
        }
        return data;
    }
}